/* 新增生产计划 */
<template>
  <a-modal
    :title="title"
    :width="1600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    :bodyStyle="bodyStyle"
    style="top:15%;height: 100%"
    destroyOnClose
  >
    <template slot="footer">
      <a-button key="back" v-if="isReadOnly" @click="handleCancel">
        关闭
      </a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <a-form :form="form" id="customerModal">
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="产品名称">
            <a-input
              placeholder="请输入产品名称"
              v-decorator.trim="['productName', validatorRules.name]"
              :disabled="disableSubmit"
            />
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="客户名称">
            <a-input
              placeholder="请输入客户名称"
              v-decorator.trim="['customerName', validatorRules.name]"
              :disabled="disableSubmit"
            />
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="任务单号">
            <a-input
              placeholder="请输入任务单号"
              v-decorator.trim="['productionNum', validatorRules.prductcode]"
              :disabled="disableSubmit"
            />
          </a-form-item>
        </a-col>
        <!--   <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="内部编码">
            <a-input
              placeholder="请输入内部合同编码"
              v-decorator.trim="['contractCode', validatorRules.prductcode]"
              :disabled="disableSubmit"
            />
            <a-select
              v-decorator.trim="['contractCode']"
              allowClear
              placeholder="请选择产品名称"
              showSearch
              @change="handleChange"
              optionFilterProp="children"
            >
              <a-select-option v-for="(item, index) in ColdDate" :key="index" :value="item.contractCode">
                {{ item.contractCode }}
              </a-select-option>
            </a-select> 
          </a-form-item>
        </a-col>-->
        <!-- <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="所属行业">
            <a-select
              :disabled="disableSubmit"
              v-decorator.trim="['industry']"
              allowClear
              placeholder="请选择"
              showSearch
              optionFilterProp="children"
            >
              <a-select-option v-for="(item, index) in industry" :key="index" :value="item.codeKey">
                {{ item.codeValue }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col> -->
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="下发时间">
            <a-date-picker
              :disabled="disableSubmit"
              style="width: 100%"
              v-decorator.trim="['issueDate', validatorRules.prductcode]"
              format="YYYY-MM-DD"
              placeholder="请选择下发时间"
              @change="dateChange"
            />
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3" v-if="createDate != '' || isShow == true">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="发货日期">
            <a-date-picker
              :disabled="disableSubmit"
              style="width: 100%"
              v-decorator.trim="['deliverDate', validatorRules.prductcode]"
              format="YYYY-MM-DD"
              placeholder="请选择发货日期"
              :disabled-date="disabledDate"
            />
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="规格型号">
            <a-input
              placeholder="请输入规格型号"
              v-decorator.trim="['spec', validatorRules.prductcode]"
              :disabled="disableSubmit"
            />
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="生产数量">
            <a-input
              placeholder="请输入生产数量"
              v-decorator.trim="['amount', validatorRules.prductcode]"
              :disabled="disableSubmit"
              type="number"
            />
          </a-form-item>
        </a-col>
        <!-- <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="型号">
            <a-input
              placeholder="请输入型号"
              v-decorator.trim="['model', validatorRules.prductcode]"
              :disabled="disableSubmit"
            />
          </a-form-item>
        </a-col> -->
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单双面">
            <!-- <a-input
              placeholder="请输入单双面"
              v-decorator.trim="['layer', validatorRules.prductcode]"
              :disabled="disableSubmit"
            /> -->
            <a-select
              :disabled="disableSubmit"
              v-decorator.trim="['layer', validatorRules.prductcode]"
              allowClear
              placeholder="请选择单双面"
            >
              <a-select-option key="单面">
                单面
              </a-select-option>
              <a-select-option key="双面">
                双面
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="基材分类">
            <a-select
              :disabled="disableSubmit"
              v-decorator.trim="['baseMaterial']"
              allowClear
              placeholder="请选择"
              showSearch
              optionFilterProp="children"
            >
              <a-select-option v-for="(item, index) in baseMaterial" :key="index" :value="item.codeKey">
                {{ item.codeValue }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="基材加工方式">
            <!-- <a-textarea placeholder="请输入备注" v-decorator.trim="['baseMaterialMethod']" auto-size /> -->
            <a-select
              :disabled="disableSubmit"
              v-decorator.trim="['baseMaterialMethod']"
              allowClear
              placeholder="请选择"
              showSearch
              optionFilterProp="children"
            >
              <a-select-option v-for="(item, index) in baseMaterialMethod" :key="index" :value="item.codeKey">
                {{ item.codeValue }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="包装材料">
            <a-select
              :disabled="disableSubmit"
              v-decorator.trim="['wrapperMaterial']"
              allowClear
              placeholder="请选择"
              showSearch
              optionFilterProp="children"
            >
              <a-select-option v-for="(item, index) in WrapperMaterial" :key="index" :value="item.codeKey">
                {{ item.codeValue }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="24 / 3">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="包装外箱">
            <a-select
              :disabled="disableSubmit"
              v-decorator.trim="['wrapperBox']"
              allowClear
              placeholder="请选择"
              showSearch
              optionFilterProp="children"
            >
              <a-select-option v-for="(item, index) in WrapperBox" :key="index" :value="item.codeKey">
                {{ item.codeValue }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="喷砂">
            <a-radio-group v-decorator.trim="['sandBlastException']" @change="changeValue" :disabled="disableSubmit">
              <a-radio :value="0">
                正常
              </a-radio>
              <a-radio :value="1">
                异常
              </a-radio>
            </a-radio-group>
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="sandBlast"
              ref="sandBlast"
              :options="editorOption"
              @focus="onEditorFocus('sandBlast')"
              @change="onEditorFocuss('sandBlast')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="表面处理">
            <a-radio-group v-decorator.trim="['surfaceTreatmentException']" :disabled="disableSubmit">
              <a-radio :value="0">
                正常
              </a-radio>
              <a-radio :value="1">
                异常
              </a-radio>
            </a-radio-group>
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="surfaceTreatment"
              ref="surfaceTreatment"
              :options="editorOption"
              @focus="onEditorFocus('surfaceTreatment')"
              @change="onEditorFocuss('surfaceTreatment')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="水清洗">
            <a-radio-group v-decorator.trim="['waterWashException']" :disabled="disableSubmit">
              <a-radio :value="0">
                正常
              </a-radio>
              <a-radio :value="1">
                异常
              </a-radio>
            </a-radio-group>
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="waterWash"
              ref="waterWash"
              :options="editorOption"
              @focus="onEditorFocus('waterWash')"
              @change="onEditorFocuss('waterWash')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="涂层-烧结">
            <a-radio-group v-decorator.trim="['coatingSinteringException']" :disabled="disableSubmit">
              <a-radio :value="0">
                正常
              </a-radio>
              <a-radio :value="1">
                异常
              </a-radio>
            </a-radio-group>
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="coatingSintering"
              ref="coatingSintering"
              :options="editorOption"
              @focus="onEditorFocus('coatingSintering')"
              @change="onEditorFocuss('coatingSintering')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="自检外观">
            <a-radio-group v-decorator.trim="['testingFacadeException']" :disabled="disableSubmit">
              <a-radio :value="0">
                正常
              </a-radio>
              <a-radio :value="1">
                异常
              </a-radio>
            </a-radio-group>
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="testingFacade"
              ref="testingFacade"
              :options="editorOption"
              @focus="onEditorFocus('testingFacade')"
              @change="onEditorFocuss('testingFacade')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="自检尺寸">
            <a-radio-group v-decorator.trim="['testingSizeException']" :disabled="disableSubmit">
              <a-radio :value="0">
                正常
              </a-radio>
              <a-radio :value="1">
                异常
              </a-radio>
            </a-radio-group>
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="testingSize"
              ref="testingSize"
              :options="editorOption"
              @focus="onEditorFocus('testingSize')"
              @change="onEditorFocuss('testingSize')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
        <a-col style="text-algin:left" :span="24">
          <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="随货资料">
            <el-upload
              :disabled="disableSubmit"
              class="avatar-uploader"
              :action="serverUrl"
              name="file"
              :headers="tokenHeader"
              :show-file-list="false"
              :data="uploadData"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
              style="display:none"
            >
            </el-upload>
            <quill-editor
              :disabled="disableSubmit"
              style="line-height:20px"
              class="editor"
              v-model="informations"
              ref="informations"
              :options="editorOption"
              @focus="onEditorFocus('informations')"
              @change="onEditorFocuss('informations')"
            >
            </quill-editor>
            <input
              type="file"
              accept="video/*"
              @change="changeVideo"
              class="uploadVideoMakdown"
              style="display: none"
            />
          </a-form-item>
        </a-col>
      </a-form>
    </a-spin>
    <div></div>
  </a-modal>
</template>
<script>
// import { devServer } from '../../../../vue.config.js'
import pick from 'lodash.pick'
import { addContractdetails, checkSupplier, editContractdetails } from '@/api/api'
import { getAction, deleteAction } from '@/api/manage'
import { BillModalMixin } from '@views/bill/mixins/BillModalMixin'
import { autoJumpNextInput } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import Vue from 'vue'
import moment from 'moment'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { postAction, putAction, uploadAction } from '../../../api/manage'
//富文本
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import * as Quill from 'quill'
import ImageResize from 'quill-image-resize-module'
Quill.register('modules/imageResize', ImageResize)
// import { Quill } from 'vue-quill-editor'
import { container, ImageExtend } from 'quill-image-extend-module'
Quill.register('modules/ImageExtend', ImageExtend)
// 这里引入修改过的video模块并注册
import Video from '../../../mixins/quill/video'
Quill.register(Video, true)

// 富文本工具栏配置
const toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
  ['blockquote', 'code-block'], // 引用  代码块
  [{ header: 1 }, { header: 2 }], // 1、2 级标题
  [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
  [{ script: 'sub' }, { script: 'super' }], // 上标/下标
  [{ indent: '-1' }, { indent: '+1' }], // 缩进
  // [{'direction': 'rtl'}],            // 文本方向
  [{ size: ['small', false, 'large', 'huge'] }], // 字体大小
  [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
  [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
  [{ font: [] }], // 字体种类
  [{ align: [] }], // 对齐方式
  ['clean'], // 清除文本格式
  ['link', 'image', 'video'] // 链接、图片、视频
]
export default {
  name: 'ProductionTaskModel',
  mixins: [BillModalMixin, JeecgListMixin],
  components: {
    quillEditor
  },
  data() {
    return {
      title: '操作',
      form: this.$form.createForm(this),
      //token header
      tokenHeader: { Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN) },
      visible: false,
      model: {},
      nature: [],
      ColdDate: [],
      disableSubmit: false,
      bomId: '',
      bomName: '',
      quantity: '',
      unit: '',
      remark: '',
      editingKey: '',
      editor: null,
      cacheData: [],
      isReadOnly: false,
      uploadUrl: '/systemConfig/upload' + '?' + `biz=fwb`,
      url: {
        lists: '/productionBom/getListById',
        Codelist: '/contractdetails/page',
        delete: '/productionPlan/remove'
      },
      dataSource: [],
      columns: [
        // { title: '物料编号', dataIndex: 'unit', width: 80, align: 'center', scopedSlots: { customRender: 'name' } },
        {
          title: '物料名称',
          dataIndex: 'bomName',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'bomName' }
        },
        { title: '单位', dataIndex: 'unit', width: 80, align: 'center', scopedSlots: { customRender: 'unit' } },
        { title: '数量', dataIndex: 'quantity', width: 80, align: 'center', scopedSlots: { customRender: 'quantity' } },
        { title: '备注', dataIndex: 'remark', width: 80, align: 'center', scopedSlots: { customRender: 'remark' } },
        {
          title: '操作',
          dataIndex: 'action',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      bodyStyle: {
        padding: '20',
        height: window.innerHeight * 0.6 + 'px',
        'overflow-y': 'auto'
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      value: '',
      key: 1,
      confirmLoading: false,
      guiG: null, //规格键名
      guiGvalue: null, //规格值
      newMapObject: null,
      vaArr: [],
      guiArr: [],
      validatorRules: {
        name: {
          rules: [
            { required: true, message: '请输入名称!' }
            // { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
          ]
        },
        prductcode: {
          rules: [{ required: true, message: '请输入!' }]
        }
      },
      //数据字典select数据
      baseMaterial: null,
      industry: null,
      baseMaterialMethod: null,
      WrapperBox: null,
      WrapperMaterial: null,
      //是否异常
      sandBlastException: 0, //喷砂
      surfaceTreatmentException: 0, //表面处理
      testingFacadeException: 0, //自检外观
      testingSizeException: 0, //自检尺寸
      waterWashException: 0, //水清洗
      coatingSinteringException: 0, //涂层-烧结
      //富文本
      sandBlast: '', //喷砂
      surfaceTreatment: '', //表面处理描述
      waterWash: '', //水清洗描述
      coatingSintering: '', //涂层-烧结
      testingFacade: '', //自检-外观描述
      testingSize: '', //自检-尺寸描述
      informations: '', //随货资料
      //富文本文字
      contentText: '',
      sandBlastText: '', //喷砂
      surfaceTreatmentText: '', //表面处理描述
      waterWashText: '', //水清洗描述
      coatingSinteringText: '', //涂层-烧结
      testingFacadeText: '', //自检-外观描述
      testingSizeText: '', //自检-尺寸描述
      informationsText: '', //随货资料
      cost: '',
      uploadData: {}, // 图片文件
      serverUrls: '/systemConfig/upload1' + '?' + `biz=fwb`, // 这里写你要上传的图片服务器地址  * post接口
      header: {
        // 有的图片服务器要求请求头需要有token，有的可以加上
        Authorization: 'Bearer '
      },
      quillUpdateImg: false, // 根据图片上传状态来确定是否显示loading动画，刚开始是false,不显示
      editorOption: {
        placeholder: '',
        theme: 'snow', // or 'bubble'
        placeholder: '请输入文章内容',
        modules: {
          toolbar: {
            container: toolbarOptions,
            // container: "#toolbar",
            handlers: {
              image: function(value) {
                if (value) {
                  let fileInput = document.querySelector('.avatar-uploader input')
                  fileInput.setAttribute('type', 'file')
                  fileInput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon')
                  fileInput.click()
                } else {
                  this.quill.format('image', false)
                }
              },
              video: function(value) {
                if (value) {
                  document.querySelector('.uploadVideoMakdown').click()
                } else {
                  return
                }
              },
              link: function(value) {
                if (value) {
                  var href = prompt('注意！只支持公众号图文链接')
                  this.quill.format('link', href)
                } else {
                  this.quill.format('link', false)
                }
              }
            }
          },
          ImageExtend: {
            loading: true,
            name: 'pictureFile',
            size: 6,
            action: 'http://101.68.86.229:8559/api/resources/pictureUploal',
            response: res => {
              return res.data
            },
            headers: xhr => {
              xhr.setRequestHeader('Authorization', window.sessionStorage.getItem('token'))
            },
            start: () => {},
            end: () => {},
            error: () => {},
            change: (xhr, formData) => {}
          },
          // 调整图片大小
          imageResize: {
            displayStyles: {
              backgroundColor: 'black',
              border: 'none',
              color: 'white'
            },
            modules: ['Resize', 'DisplaySize', 'Toolbar']
          }
        }
      },
      editor_ref: '',
      // toolbar标题
      titleConfig: [
        { Choice: '.ql-insertMetric', title: '跳转配置' },
        { Choice: '.ql-bold', title: '加粗' },
        { Choice: '.ql-italic', title: '斜体' },
        { Choice: '.ql-underline', title: '下划线' },
        { Choice: '.ql-header', title: '段落格式' },
        { Choice: '.ql-strike', title: '删除线' },
        { Choice: '.ql-blockquote', title: '块引用' },
        { Choice: '.ql-code', title: '插入代码' },
        { Choice: '.ql-code-block', title: '插入代码段' },
        { Choice: '.ql-font', title: '字体' },
        { Choice: '.ql-size', title: '字体大小' },
        { Choice: '.ql-list[value="ordered"]', title: '编号列表' },
        { Choice: '.ql-list[value="bullet"]', title: '项目列表' },
        { Choice: '.ql-direction', title: '文本方向' },
        { Choice: '.ql-header[value="1"]', title: 'h1' },
        { Choice: '.ql-header[value="2"]', title: 'h2' },
        { Choice: '.ql-align', title: '对齐方式' },
        { Choice: '.ql-color', title: '字体颜色' },
        { Choice: '.ql-background', title: '背景颜色' },
        { Choice: '.ql-image', title: '图像' },
        { Choice: '.ql-video', title: '视频' },
        { Choice: '.ql-link', title: '添加链接' },
        { Choice: '.ql-formula', title: '插入公式' },
        { Choice: '.ql-clean', title: '清除字体格式' },
        { Choice: '.ql-script[value="sub"]', title: '下标' },
        { Choice: '.ql-script[value="super"]', title: '上标' },
        { Choice: '.ql-indent[value="-1"]', title: '向左缩进' },
        { Choice: '.ql-indent[value="+1"]', title: '向右缩进' },
        { Choice: '.ql-header .ql-picker-label', title: '标题大小' },
        { Choice: '.ql-header .ql-picker-item[data-value="1"]', title: '标题一' },
        { Choice: '.ql-header .ql-picker-item[data-value="2"]', title: '标题二' },
        { Choice: '.ql-header .ql-picker-item[data-value="3"]', title: '标题三' },
        { Choice: '.ql-header .ql-picker-item[data-value="4"]', title: '标题四' },
        { Choice: '.ql-header .ql-picker-item[data-value="5"]', title: '标题五' },
        { Choice: '.ql-header .ql-picker-item[data-value="6"]', title: '标题六' },
        { Choice: '.ql-header .ql-picker-item:last-child', title: '标准' },
        { Choice: '.ql-size .ql-picker-item[data-value="small"]', title: '小号' },
        { Choice: '.ql-size .ql-picker-item[data-value="large"]', title: '大号' },
        { Choice: '.ql-size .ql-picker-item[data-value="huge"]', title: '超大号' },
        { Choice: '.ql-size .ql-picker-item:nth-child(2)', title: '标准' },
        { Choice: '.ql-align .ql-picker-item:first-child', title: '居左对齐' },
        { Choice: '.ql-align .ql-picker-item[data-value="center"]', title: '居中对齐' },
        { Choice: '.ql-align .ql-picker-item[data-value="right"]', title: '居右对齐' },
        { Choice: '.ql-align .ql-picker-item[data-value="justify"]', title: '两端对齐' }
      ],
      createDate: '',
      isShow: false
    }
  },
  //文字溢出隐藏
  filters: {
    ellipsis(val, length) {
      if (val) {
        if (val.length > length) {
          return val.substring(0, length) + '...'
        } else {
          return val
        }
      }
    }
  },
  mounted() {
    this.getCode()
    //数据字典
    this.getDictionary()
    this.getIndustry()
    this.getBaseMaterialMethod()
    this.getWrapperMaterial()
    this.getWrapperBox()
    this.cacheData = this.dataSource.map(item => ({ ...item }))
    console.log(window._CONFIG['domianURL'], 'API_CONFIG')
  },
  updated() {
    if (this.visible == false) return
    let arr = document.querySelectorAll('.quill-editor')
    arr.forEach(e => {
      for (let item of this.titleConfig) {
        let tip = e.querySelector(item.Choice)
        if (!tip) continue
        tip.setAttribute('title', item.title)
      }
    })
  },
  computed: {
    serverUrl: function() {
      return `${window._CONFIG['domianURL']}${this.serverUrls}`
      // return `api${this.url.importExcelUrl}`
    }
  },
  methods: {
    dateChange(date, dateString) {
      console.log(841, date, dateString)
      this.createDate = dateString
    },
    moment,
    disabledDate(current) {
      console.log(current, 'eee')
      // Can not select days before today and today
      return current && current < moment(this.createDate, 'YYYY-MM-DD')
    },
    changeValue(e) {
      console.log(e.target.value, 'xxxxx')
    },
    changeVideo(e) {
      debugger
      let file = e.target.files[0]
      const formData = new FormData()
      console.log(this.editor_ref, 'this.editor_ref')
      formData.append('file', file)
      this.videoLoading = true
      postAction(this.serverUrls, formData).then(res => {
        let quill = this.$refs[this.editor_ref].quill
        if (res.code == 200) {
          this.$message.success('上传成功')
          this.videoLoading = false
          let length = quill.getSelection().index //光标位置
          if (window._CONFIG['domianURL'] == '/erp-web/api') {
            let a = res.data.indexOf('/systemConfig')
            let b = 'http://shanxihengyue.com:8081/erp-web/api'
            let c = b + res.data.substring(a)
            quill.insertEmbed(length, 'video', c)
          } else {
            quill.insertEmbed(length, 'video', res.data)
          }
          quill.setSelection(length + 1) //光标后移一位
        } else {
          this.$message.warning('上传失败')
        }
      })
    },
    getDictionary() {
      const params = {
        codeType: 'baseMaterial'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.baseMaterial = res.data.records

          // this.baseMaterialMethod = res.data.records
        }
      })
    },
    getWrapperBox() {
      const params = {
        codeType: 'WrapperBox'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.WrapperBox = res.data.records
        }
      })
    },
    getWrapperMaterial() {
      const params = {
        codeType: 'WrapperMaterial'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.WrapperMaterial = res.data.records
        }
      })
    },
    getIndustry() {
      const params = {
        codeType: 'industry'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.industry = res.data.records
        }
      })
    },
    getBaseMaterialMethod() {
      const params = {
        codeType: 'baseMaterialMethod'
      }
      getAction('/generalDict/getList', params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.baseMaterialMethod = res.data.records
        }
      })
    },
    onEditorFocus(editor_ref) {
      this.editor_ref = editor_ref
    },
    onEditorFocuss(editor_ref) {
      if (this.$refs[this.editor_ref]) {
        var quill = this.$refs[this.editor_ref].quill
        switch (this.editor_ref) {
          case 'sandBlast':
            this.sandBlastText = quill.getText()
            break
          case 'surfaceTreatment':
            this.surfaceTreatmentText = quill.getText()
            break
          case 'waterWash':
            this.waterWashText = quill.getText()
            break
          case 'coatingSintering':
            this.coatingSinteringText = quill.getText()
            break
          case 'testingFacade':
            this.testingFacadeText = quill.getText()
            break
          case 'testingSize':
            this.testingSizeText = quill.getText()
            break
          default:
            this.informationsText = quill.getText()
            break
        }
      }
    },
    handleChange(value) {
      this.ColdDate.forEach(item => {
        if (item.contractCode == value) {
          this.form.setFieldsValue({ contractNum: item.contractNum })
        }
      })
    },
    //获取合同数据
    getCode() {
      getAction(this.url.Codelist).then(res => {
        this.ColdDate = res.data.records
      })
    },
    myhandleChange(value, record, column) {
      const newData = [...this.dataSource]
      if (record.key) {
        var target = newData.find(item => record.key === item.key)
      } else {
        var target = newData.find(item => record.id === item.id)
      }
      if (target) {
        target[column] = value
        this.dataSource = newData
      }
    },
    getTableList(record) {
      this.loading = true
      let params = {}
      //规格属性管理查询条件
      params.productionId = record.id
      //页码字段未统一
      params.current = this.ipagination.current
      params.currentPage = this.ipagination.current
      params.size = this.ipagination.pageSize
      params.pageSize = this.ipagination.pageSize
      getAction(this.url.lists, params).then(res => {
        if (res.code === 200 || res.code === 10000) {
          if (res.data) {
            this.dataSource = res.data
          }
        } else {
          this.$message.warning(res.data || '数据获取失败')
        }
      })
      this.loading = false
    },
    add() {
      this.edit()
    },
    edit(record) {
      this.form.resetFields()
      let a = null
      if (record && record.id) {
        this.isShow = true
        this.confirmLoading = true
        let params = { id: record.id }
        getAction('	productionPlan/getById', params).then(res => {
          if (res.code == 10000) {
            this.confirmLoading = false
          }
          console.log(res, 'res')
          a = res.data
          this.model = Object.assign({}, a)
          console.log(this.model, 'record')
          this.edit2(record)
        })
      }
      this.visible = true
    },
    edit2(record) {
      this.$nextTick(() => {
        setTimeout(() => {
          //如果有record则走编辑,日期回显
          if (record) {
            console.log(record, 'record')
            console.log(this.model, 'this.model.issueDatethis.model.issueDate')
            var issueDate = this.$moment(this.model.issueDate)
            this.form.setFieldsValue({ issueDate: issueDate })
            this.createDate = issueDate
            var deliverDate = this.$moment(this.model.deliverDate)
            this.form.setFieldsValue({ deliverDate: deliverDate })
            //富文本回显
            this.testingSize = this.model.testingSize
            this.surfaceTreatment = this.model.surfaceTreatment
            this.testingFacade = this.model.testingFacade
            this.waterWash = this.model.waterWash
            this.coatingSintering = this.model.coatingSintering
            this.sandBlast = this.model.sandBlast
            this.informations = this.model.informations
            //按钮回显

            this.form.setFieldsValue(
              pick(
                this.model,
                'productionNum',
                'businessLeader',
                'industry',
                'customerName',
                'spec',
                'amount',
                'layer',
                'contractCode',
                'baseMaterial',
                'baseMaterialMethod',
                'wrapperBox',
                'wrapperMaterial',
                'productName',
                'sandBlastException',
                'surfaceTreatmentException',
                'testingFacadeException',
                'testingSizeException',
                'waterWashException',
                'coatingSinteringException'
              )
            )
            autoJumpNextInput('customerModal')
          }
        }, 400)
      })
    },
    close() {
      this.$emit('close')
      this.model = {}
      this.visible = false
      this.sandBlast = ''
      this.surfaceTreatment = ''
      this.waterWash = ''
      this.coatingSintering = ''
      this.testingFacade = ''
      this.testingSize = ''
      this.informations = ''
      this.isReadOnly = false
      this.createDate = ''
      this.isShow = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          console.log(this.model, 'this.modelthis.model')
          let formData = Object.assign(this.model, values)
          formData.sandBlast = this.sandBlast
          formData.coatingSintering = this.coatingSintering
          formData.waterWash = this.waterWash
          formData.testingSize = this.testingSize
          formData.testingFacade = this.testingFacade
          formData.surfaceTreatment = this.surfaceTreatment
          formData.informations = this.informations
          formData.deliverDate = this.$moment(this.model.deliverDate).format('YYYY-MM-DD')
          formData.issueDate = this.$moment(this.model.issueDate).format('YYYY-MM-DD')
          console.log(this.model, 'this.model')
          console.log(formData, 'formData')
          let obj
          if (!this.model.id) {
            obj = postAction('/productionPlan/save', formData)
          } else {
            obj = postAction('/productionPlan/modify', formData)
          }
          obj
            .then(res => {
              if (res.code === 200 || res.code === 10000) {
                this.$message.success('保存成功')
                that.$emit('ok')
              } else {
                that.$message.warning(res.message || '数据获取失败')
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    validateSupplierName(rule, value, callback) {
      let params = {
        name: value,
        type: '客户',
        id: this.model.id ? this.model.id : 0
      }
      checkSupplier(params).then(res => {
        if (res && res.code === 200) {
          if (!res.data.status) {
            callback()
          } else {
            callback('名称已经存在')
          }
        } else {
          callback(res.data)
        }
      })
    },
    //富文本
    uploadSuccess(res, file) {
      console.log(file, 'filessssss')
      // 获取富文本组件实例
      var ref_el = this.$refs[this.editor_ref]
      console.log(ref_el)
      let quill = this.$refs[this.editor_ref].quill
      // 如果上传成功
      if (res.code == 200 && res.data) {
        this.$message.success('上传成功')
        // 获取光标所在位置
        let length = quill.getSelection().index
        if (window._CONFIG['domianURL'] == '/erp-web/api') {
          let a = res.data.indexOf('/systemConfig')
          let b = 'http://shanxihengyue.com:8081/erp-web/api'
          let c = b + res.data.substring(a)
          quill.insertEmbed(length, 'image', c)
        } else {
          quill.insertEmbed(length, 'image', res.data)
        }
        // 插入图片  res.info为服务器返回的图片地址  http://192.168.0.122:8033/systemConfig/static/fwb/1/背景_1665822126457.png
        // quill.insertEmbed(length, 'image', res.data)

        // 调整光标到最后
        quill.setSelection(length + 1)
      } else {
        this.$message.error('图片插入失败')
      }
      // this.quillUpdateImg = false
    },
    uploadError() {
      // this.quillUpdateImg = false
      this.$message.error('图片插入失败')
    },
    beforeUpload(file) {
      // this.quillUpdateImg = true
      console.log(file, 'filessssss')
    }
  }
}
</script>
<style scoped>
#billModal {
  margin: 20px 0;
}
.editable-row-operations a {
  margin-right: 8px;
}
@import '~@assets/less/common.less';
</style>
